package com.dimples.dd.system.controller;

import com.dimples.dd.common.constant.DDServerConstant;
import com.dimples.dd.common.pojo.PageResult;
import com.dimples.dd.log.core.annotation.ApiLog;
import com.dimples.dd.log.core.enums.OperateTypeEnum;
import com.dimples.dd.system.model.query.OAuth2AccessTokenPageQuery;
import com.dimples.dd.system.model.vo.OAuth2AccessTokenPageVO;
import com.dimples.dd.system.service.Oauth2AuthorizationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Tag(name = "07.OAuth2.0 令牌")
@RestController
@RequestMapping("oauth2-token")
@RequiredArgsConstructor
public class OAuth2TokenController {

    private final Oauth2AuthorizationService oauth2TokenService;

    @GetMapping("/page")
    @Operation(summary = "获得访问令牌分页", description = "只返回有效期内的")
    @PreAuthorize("@ss.hasPerm('system:oauth2-token:page')")
    @ApiLog(operateType = OperateTypeEnum.SELECT, applicationName = DDServerConstant.DD_SERVER_SYSTEM)
    public PageResult<OAuth2AccessTokenPageVO> selectAccessTokenPage(@Valid OAuth2AccessTokenPageQuery pageQuery) {
        return this.oauth2TokenService.selectAccessTokenPage(pageQuery);
    }

}
